package javacore.abstraction;

public class FinalVariable {
	// "final" guarantees that a variable must be initialized before end of object initializer code.
	final double PI1 = Math.atan(1) * 4;
	final double PI2 = getPI();
	final double PI3;
	final double PI4;
	final double wrongPI = 22.0 / 7.0;
	
	{
		// We can initialize final vars in initializer block
		PI3 = Math.atan(1) * 4;
	}
	void Test(){
		// We can not initialize final variables in non constructor method
		//PI3 = 22 / 7; // Error
	}
	
	FinalVariable (){
		// We can initialize final vars in Constructor
		PI4 = Math.atan(1) * 4;
	}
	
	public static void main (String args[]){
		new FinalVariable().print();
	}
	
	double getPI(){
		return Math.atan(1) * 4;
	}
	
	void print(){
		System.out.printf("PI1 = %f, PI2 = %f, PI3 = %f, PI4 = %f", PI1, PI2, PI3,PI4);
		System.out.println("\nWrong value of PI = " + wrongPI);
	}

}
